{% extends "base.html" %}

{% if recipe %}
	{% block title %}{% if pre_title %}{{ pre_title }} - {% endif %}{{recipe.title}}{% endblock %}
{% endif %}

{% load template_filters %}
{% block content %}
	{% if beginning %}<div id="filter_info">{{ beginning }}</div>{% endif %}
	{% if recipe %}
		{% if user.is_authenticated and user = recipe.user %}
			<h1><a href="/edit_recipe/{{ recipe.id }}/">{{ recipe.title }}</a></h1>
		{% else %}
		<h1>{{ recipe.title }}</h1>
		{% endif %}
		<b>{{ recipe.user.username }}</b> on {{ recipe.pub_date }}:<br />
		<table id="recipe_information">
			<tr>
				<td class="table-left">All - in - all:</td>
				<td>
		{% if rating != "None" %}
			{% for i in 25|get_range %}
	    		<input name="pub_rating" disabled="disabled" value="{{ i|get_value }}" type="radio" class="public {split:5}"{% if i|get_value == rating %} checked="checked"{% endif %} />
			{% endfor %}
		{% else %}
			No ratings yet&nbsp;&nbsp;&nbsp;
		{% endif %}
		</td>
		<td class="table-left">Servings:</td><td> {{ recipe.servings }} </td>
		<td class="table-left"> Difficulty: </td><td>{{ recipe.difficulty }} </td>
	
		</tr>
			<tr>
				{% if user.is_authenticated %}
			<td class="table-left">Your rating:</td>
			<td>
			<form id="rating_form" action="/rate/" method="post">
				{% for i in 5|get_range %}
					<input name="rating" value = "{{ i }}" type="radio" class="star"{% if i == rating_user %} checked="checked"{% endif %}/>
				{% endfor %}
				<input type="hidden" value="{{ recipe.pk }}" name="recipe">
			</form>
		
			
		
			</td>
			{% else %}
			<td></td><td></td>
			{% endif %}
			<td class="table-left">Vegetarian: </td><td> {{ recipe.vegetarian }} </td>
			{% if recipe.kcal %} <td class="table-left"> Energy: </td> <td> {{ recipe.kcal }} kcal</td> {% endif %}
			</tr>
			</table>
		
<script>
	$('.star').rating({
		callback: function(value, link) {
			this.form.submit();
		}
	});
	
		$('input.public').rating();

</script>
		<div id="ingredients">
		<h2>Ingredients:</h2>
		{% if ingredients %}
		    <table>
		    {% for ingredient in ingredients %}
		        <tr>
		        	<td>{{ ingredient.amount }} {{ ingredient.unit }}</td>
		        	<td>{{ ingredient.name }}</td>
		        </tr>
		    {% endfor %}
		    </table>
		{% else %}
		    <p>No ingredients available.</p>
		{% endif %}
		</div>
		<div id="description">
		<h2>Description:</h2>
		<p>{{ recipe.description }}</p>
		</div>
	{% else %}
	    <p>This recipe does not exist.</p>
	{% endif %}
{% endblock %}

